package com.yzy.controller;

import com.yzy.dao.PatientDao;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class PatientLonginServlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pphone,ppass;

        PatientDao dao = new PatientDao();
        int result=0;
        //1utf-8
        request.setCharacterEncoding("utf-8");
        //2读取请求体参数
        pphone = request.getParameter("pphone");
        ppass = request.getParameter("ppass");

        ServletContext application = request.getServletContext();
        application.setAttribute("PlonginPhone2",pphone);


        //3调用dao
        result = dao.longin(pphone,ppass);
        System.out.println(result);
        //4调用响应对象
        if(result==1){
            response.sendRedirect("/myWeb/patient/book/find");


        }else{
            System.out.println(result);
            response.sendRedirect("/myWeb/adminlongin_error.html");
        }
    }
}
